package org.coody.datafuzzer.instance;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;

import org.coody.framework.jdbc.JdbcHandle;

public class TableInstance {

	private JdbcHandle jdbcHandle;

	public TableInstance(JdbcHandle jdbcHandle) {
		super();
		this.jdbcHandle = jdbcHandle;
	}

	public JdbcHandle getJdbcHandle() {
		return jdbcHandle;
	}

	public void setJdbcHandle(JdbcHandle jdbcHandle) {
		this.jdbcHandle = jdbcHandle;
	}

	public Set<String> getTables() throws SQLException {
		Connection connection = jdbcHandle.getDataSource().getConnection();
		DatabaseMetaData metaData = connection.getMetaData();
		ResultSet resultSet = metaData.getTables(null, null, null, new String[] { "TABLE" });
		Set<String> tables = new HashSet<String>();
		while (resultSet.next()) {
			tables.add(resultSet.getString(3));
		}
		return tables;
	}
}
